package com.itheima.test03;

import java.io.*;
import java.net.Socket;

/*
tcp 发送端
发送数据

同时 接受 服务端 传回的消息
 */
public class ClientDemo {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 9999);
        OutputStream os = socket.getOutputStream();
        //字符 ->字节
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        writer.write("你瞅啥");
        writer.flush();
        //告诉 服务端  我数据已经传完了
        socket.shutdownOutput();

        //接受服务器给回的响应
        InputStream is = socket.getInputStream();
        //字节到字符
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            System.out.println(s);
        }
        //is.close();
        socket.close();

    }
}
